package cn.xiaoyangh.basic.service.impl;

import cn.xiaoyangh.basic.domain.BaseDomain;
import cn.xiaoyangh.basic.mapper.BaseMapper;
import cn.xiaoyangh.basic.query.BaseQuery;
import cn.xiaoyangh.basic.service.IBaseService;
import cn.xiaoyangh.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> b;


    @Override
    public void save(T t) {
        b.save(t);
    }

    @Override
    public void remove(Long id) {
        b.remove(id);
    }

    @Override
    public void update(T t) {
        b.update(t);
    }


    @Override
    public List loadAll() {
        return b.findAll();
    }

    @Override
    public T loadById(Long id) {
        return b.loadById(id);
    }

    @Override
    public PageList<T> queryData(BaseQuery bq) {
        Integer count = b.count(bq);
        List<T> list = b.loadByQuery(bq);
        PageList<T> dlist = new PageList<>(count, list);
        return dlist;
    }

    @Override
    public void deleteAll(List list) {
        b.deletAll(list);
    }
}
